#ifndef __TILT_INLINE_H__
#define __TILT_INLINE_H__

#define gainFactor 5

inline void calcGain(const double amp, const double gain, double *lgain, double *hgain)
{
  double g1, g2;
  
  if(gain > 0)
  {
    g1 = -gainFactor * gain;
    g2 = gain;
  } else {
    g1 = -gain;
    g2 = gainFactor * gain;
  }

  *lgain = exp(g1/amp)-1;
  *hgain = exp(g2/amp)-1;
}

inline void calcFilter(const double f, const double sr, double *a0, double *b1) {
  double omega = 2* M_PIl * f;
  double n = 1 / (sr + omega);
  *a0 = 2 * omega * n;
  *b1 = (sr - omega) * n;
}

inline void calcCoeff(const float slice, const double a0, const double b1, double *lp) { *lp = a0 * slice + b1 * (*lp); }
inline void applyCoeff(const float slice, const double lgain, const double hgain, const double lp, float *out) { *out = slice + (lgain * lp) + (hgain * (slice-lp)); }

inline float killDenorm(float val)
{
  static const double denorm = 1.0e-56;
  val += denorm;
  val -= denorm;
  return val;
}

#endif //  __TILT_INLINE_H__
